package com.minhua.jijiehao2.mainframe.launcher.splashactivity.impl

import com.minhua.jijiehao2.base.BaseApplication
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.http.*
import com.minhua.jijiehao2.mainframe.launcher.splashactivity.imp.ISplashModel
import com.minhua.jijiehao2.utils.AppUtils
import com.minhua.jijiehao2.utils.SPUtils

class SplashModel : ISplashModel {
    override fun getSwitchStatus(map: ParamsMap, callBack: CallBack<Int>) {
        HttpController<Int>().doHttp(
                ApiClient.getInstance().api.getSwitchStatus(map.toRequestBody()),
                object : BaseSubscriber<Int>() {
                    override fun dealData(t: BaseBean<Int>) {
                        callBack.onSuccess(t)
                    }
                },
                false
        )
    }

    override fun saveSwitch(switch: Int) {
        var currentCode = AppUtils.getVersionCode(BaseApplication.APP)
        if (currentCode <= switch) {
            SPUtils.put(DefineKey.SWITCH, 1)
        } else {
            SPUtils.put(DefineKey.SWITCH, 0)
        }

    }
}